package com.lmc.chatroom.controller;

import com.lmc.chatroom.model.Friend;
import com.lmc.chatroom.model.Result;
import com.lmc.chatroom.model.User;
import com.lmc.chatroom.service.friendService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/friend")
public class friendController {

    @Autowired
    friendService friendService;

    @RequestMapping("/getFriendList")
    public Result getFriendList(HttpServletRequest request) {
        log.info("getFriendList");
        HttpSession session = request.getSession(false);
        if (session == null) {
            log.info("session为空，请登录");
            return Result.fail("获取好友列表失败！");
        }
        User user = (User) session.getAttribute("user");
        if (user == null) {
            log.info("用户信息为空");
            return Result.fail("获取好友列表失败！");
        }
        List<Friend> list = friendService.getFriendList(user.getUserId());
        log.info("getFriendList"+list);
        return Result.success(list);
    }
}
